<?php


namespace app\libs\tool;


use app\libs\exception\ServerError;
use think\facade\Cache;

class CacheTool
{
    /**
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * @throws ServerError
     */
    public function setCache($key, $value, $allowTime = 300)
    {
        if (!$key || !$value) {
            throw new ServerError(['msg' => '键值都不能为空']);
        }

        Cache::store('redis')->set($key, $value, $allowTime);
    }

    /**
     * @throws \Psr\SimpleCache\InvalidArgumentException
     */
    public static function getCache($key)
    {
        return Cache::store('redis')->get($key);
    }

    public static function getCurrentUserId()
    {
        return self::getCache(config('secure.current_user_id'));
    }
}